﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using OreSystem.BLL;
using OreSystem.Entities;
namespace MainFrom
{
    public partial class MainFrom : Form
    {
        public User User { get; set; }
        public MainFrom()
        {
            InitializeComponent();
        }

        private void 二层管理ToolStripMenuItem_Click(object sender, EventArgs e) {
            LevelForm levelFrom = new LevelForm();
            levelFrom.layer = 1;
            levelFrom.ShowDialog();
        }

        private void 三层管理ToolStripMenuItem_Click(object sender, EventArgs e) {
            LevelForm levelFrom = new LevelForm();
            levelFrom.layer = 2;
            levelFrom.ShowDialog();
        }

        private void 添加车辆ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            CarFrom carFrom = new CarFrom();
            carFrom.ShowDialog();
        }

        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            ItemEdit itemEditFrom = new ItemEdit();
            itemEditFrom.NewItem = new Item();
            itemEditFrom.Type = 1;
            itemEditFrom.ShowDialog();
        }

        private void toolStripButton3_Click(object sender, EventArgs e)
        {
            ItemEdit itemEditFrom = new ItemEdit();
            itemEditFrom.NewItem = new Item();
            itemEditFrom.Type = 2;
            itemEditFrom.ShowDialog();
        }

        private void 挖机编辑ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ExcvavtorForm excForm = new ExcvavtorForm();
            excForm.ShowDialog();
        }

        private void MainFrom_Load(object sender, EventArgs e)
        {
            if (User == null) {
                MessageBox.Show("没有登录！请登录");
                this.Close();
            }
            
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
            this.MaximizeBox = false;
            toolStripStatusLabel3.Text = "用户："+User.UserName;
            timer1.Start();
        }

        private void 添加车辆ToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            CartEdit carEdit = new CartEdit();
            carEdit.Plevels = new LevelBll().GetLevelByLevel(2);
            carEdit.NewCar = null;
            if (carEdit.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {

            }
        }

        private void 添加挖机ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ExcvavtorEditForm excForm = new ExcvavtorEditForm();
            excForm.Plevels = new LevelBll().GetLevelByLevel(2);
            excForm.newCar = null;
            if (excForm.ShowDialog()== System.Windows.Forms.DialogResult.OK)
            {

            }
        }       

        private void 车辆信息输入ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ItemEdit itemEditFrom = new ItemEdit();
            itemEditFrom.NewItem = new Item();
            itemEditFrom.Type = 1;
            itemEditFrom.ShowDialog();
        }

        private void 车辆信息编辑ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ItemForm itemForm = new ItemForm();
            itemForm.Type = 1;
            itemForm.ShowDialog();
        }

        private void 挖机信息输入ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ItemEdit itemEditFrom = new ItemEdit();
            itemEditFrom.NewItem = new Item();
            itemEditFrom.Type = 2;
            itemEditFrom.ShowDialog();
        }

        private void 挖机信息编辑ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ItemForm itemForm = new ItemForm();
            itemForm.Type = 2;
            itemForm.ShowDialog();
        }

        private void timer1_Tick(object sender, EventArgs e) {
            toolStripStatusLabel3.Text = "当前时间为："+DateTime.Now.ToString();
        }

        private void toolStripStatusLabel3_Click(object sender, EventArgs e) {

        }

        private void toolStripButton4_Click(object sender, EventArgs e) {
            new Report_HuiZong().Show();
        }

        private void 添加用户ToolStripMenuItem_Click(object sender, EventArgs e) {
            new UserForm().ShowDialog();
        }

        private void 用户管理ToolStripMenuItem_Click(object sender, EventArgs e) {
            new UserForm().ShowDialog();
        }

        private void 修改密码ToolStripMenuItem_Click(object sender, EventArgs e) {
            EditPassWordForm pwForm = new EditPassWordForm();
            pwForm.User = this.User;
            if (pwForm.ShowDialog() == System.Windows.Forms.DialogResult.OK) {
                
            }
        }

        private void 重新登录ToolStripMenuItem_Click(object sender, EventArgs e) {

            this.Close();
            
        }

        private void 退出ToolStripMenuItem_Click(object sender, EventArgs e) {
            Application.Exit();
        }

        private void MainFrom_FormClosing(object sender, FormClosingEventArgs e) {
            if (e.CloseReason == CloseReason.ApplicationExitCall) {
                if (MessageBox.Show("确定直接退出系统吗!", "退出系统", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes) {

                }
                else {
                    e.Cancel = true;
                }
            }
            else if (e.CloseReason == CloseReason.UserClosing) {
                if (MessageBox.Show("确定要注销系统？", "系统提示", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes) {
                    ((System.Windows.Forms.Form)this.Tag).Visible = true;
                    this.DialogResult = DialogResult.Cancel;
                }
                else {
                    e.Cancel = true;
                }
            }
            
           
            
        }

        private void 数据备份ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            new BackDataForm().Show();
        }
    }
}
